local shengongcurse = fk.CreateSkill{
    name = "ym1__curse"
}
Fk:loadTranslationTable{
    ["@ym1__shengongA1"] = "锋利",
    [":@ym1__shengongA1"] = "你使用伤害牌无视目标防具。",
    ["@ym1__shengongA2"] = "火焰附加",
    [":@ym1__shengongA2"] = "结束阶段，本回合受到过伤害的角色受到1点火焰伤害。",
    ["@ym1__shengongA3"] = "掠夺",
    [":@ym1__shengongA3"] = "你使用【杀】造成伤害后，获得目标一张牌。",
    ["@ym1__shengongA3-prompt"] = "掠夺：获得目标一张牌",
    ["@ym1__shengongA4"] = "引雷",
    [":@ym1__shengongA4"] = "你使用【杀】时，与目标进行“浮雷”判定。",
    ["@ym1__shengongA5"] = "击退",
    [":@ym1__shengongA5"] = "你造成伤害后，目标获得一个“钝”标记至本轮结束。",

    ["@ym1__shengongB1"] = "保护",
    [":@ym1__shengongB1"] = "此装备进入你的装备区时，你获得1点护甲。",
    ["@ym1__shengongB2"] = "缓冲",
    [":@ym1__shengongB2"] = "你受到大于1点的伤害时，弃置此牌防止之。",
    ["@ym1__shengongB3"] = "荆棘",
    [":@ym1__shengongB3"] = "你受到其他角色的伤害后，弃置伤害来源一张牌。",
    ["@ym1__shengongB4"] = "水下呼吸",
    [":@ym1__shengongB4"] = "你的手牌上限+2。",

    ["@ym1__shengongC1"] = "效率",
    [":@ym1__shengongC1"] = "你使用【桃】或【酒】时，牌面数值+1。",
    ["@ym1__shengongC2"] = "时运",
    [":@ym1__shengongC2"] = "你的判定牌生效前，可以亮出牌堆顶的一张牌代替之。",
    ["@ym1__shengongC3"] = "忠诚",
    [":@ym1__shengongC3"] = "此牌本回合首次离开装备区后，置入你的手牌区。",
    ["@ym1__shengongC4"] = "绑定诅咒",
    [":@ym1__shengongC4"] = "你不能再使用相同副类别的装备牌。",
    ["@ym1__shengongC5"] = "精准采集",
    [":@ym1__shengongC5"] = "每回合首次摸牌时，改为摸四张牌再弃置两张牌。",
    ["@ym1__shengongC6"] = "经验修补",
    [":@ym1__shengongC6"] = "此装备魔咒上限为5，你回复体力时，为此装备再添加1条魔咒。",

    ["@ym1__shengongD1"] = "无限",
    [":@ym1__shengongD1"] = "你因使用失去【杀】时，防止之。",
    ["@ym1__shengongD2"] = "冰霜行者",
    [":@ym1__shengongD2"] = "你抵消牌后，使用者对其自己造成1点冰冻伤害。",

    ["@@ym1__shengongA1"] = "锋利",
    [":@@ym1__shengongA1"] = "<font color='#cd9bff'>你使用伤害牌无视目标防具。",
    ["@@ym1__shengongA2"] = "火焰附加",
    [":@@ym1__shengongA2"] = "<font color='#cd9bff'>结束阶段，本回合受到过伤害的角色受到1点火焰伤害。",
    ["@@ym1__shengongA3"] = "掠夺",
    [":@@ym1__shengongA3"] = "<font color='#cd9bff'>你使用【杀】造成伤害后，获得目标一张牌。",
    ["@@ym1__shengongA3-prompt"] = "掠夺：获得目标一张牌",
    ["@@ym1__shengongA4"] = "引雷",
    [":@@ym1__shengongA4"] = "<font color='#cd9bff'>你使用【杀】时，与目标进行“浮雷”判定。",
    ["floating_thunder"] = "浮雷",
    ["@@ym1__shengongA5"] = "击退",
    [":@@ym1__shengongA5"] = "<font color='#cd9bff'>你造成伤害后，目标获得一个“钝”标记至本轮结束。",
    ["@[desc]ym1__dun-round"] = "钝",
    ["#ym1__dunxi"] = "钝袭",
    [":ym1__dun-round"] = "有“钝”标记的角色使用基本牌或锦囊牌时，"..
    "若目标数为1且没有处于濒死状态的角色，其移去一个“钝”，然后目标改为随机一名角色。"..
    "若随机的目标与原本目标相同，则其于此牌结算结束后失去1点体力并结束出牌阶段。",

    ["@@ym1__shengongB1"] = "保护",
    [":@@ym1__shengongB1"] = "<font color='#cd9bff'>此装备进入你的装备区时，你获得1点护甲。",
    ["@@ym1__shengongB2"] = "缓冲",
    [":@@ym1__shengongB2"] = "<font color='#cd9bff'>你受到大于1点的伤害时，弃置此牌防止之。",
    ["@@ym1__shengongB3"] = "荆棘",
    [":@@ym1__shengongB3"] = "<font color='#cd9bff'>你受到其他角色的伤害后，弃置伤害来源一张牌。",
    ["@@ym1__shengongB3-prompt"] = "荆棘：弃置伤害来源一张牌",
    ["@@ym1__shengongB4"] = "水下呼吸",
    [":@@ym1__shengongB4"] = "<font color='#cd9bff'>你的手牌上限+2。",

    ["@@ym1__shengongC1"] = "效率",
    [":@@ym1__shengongC1"] = "<font color='#cd9bff'>你使用【桃】或【酒】时，牌面数值+1。",
    ["@@ym1__shengongC2"] = "时运",
    [":@@ym1__shengongC2"] = "<font color='#cd9bff'>你的判定牌生效前，可以亮出牌堆顶的一张牌代替之。",
    ["@@ym1__shengongC2-prompt"] = "是否发动 时运，亮出牌堆顶的一张牌代替判定牌",
    ["@@ym1__shengongC3"] = "忠诚",
    [":@@ym1__shengongC3"] = "<font color='#cd9bff'>此牌本回合首次离开装备区后，置入你的手牌区。",
    ["@@ym1__shengongC4"] = "绑定诅咒",
    [":@@ym1__shengongC4"] = "<font color='#800000'>你不能再使用相同副类别的装备牌。",
    ["@@ym1__shengongC5"] = "精准采集",
    [":@@ym1__shengongC5"] = "<font color='#cd9bff'>每回合首次摸牌时，改为摸四张牌再弃置两张牌。",
    ["@@ym1__shengongC6"] = "经验修补",
    [":@@ym1__shengongC6"] = "<font color='#cd9bff'>此装备魔咒上限为5，你回复体力时，为此装备再添加1条魔咒。",

    ["@@ym1__shengongD1"] = "无限",
    [":@@ym1__shengongD1"] = "<font color='#cd9bff'>你因使用失去【杀】时，防止之。",
    ["@@ym1__shengongD2"] = "冰霜行者",
    [":@@ym1__shengongD2"] = "<font color='#cd9bff'>你抵消牌后，使用者对其自己造成1点冰冻伤害。",
}

---检测有无指定的合法附魔魔咒
---@param card integer | Card @ 卡牌
---@param curse string @ 魔咒
---@param sub_type? integer @ 指定副类别
local function hasCurse(card,curse,sub_type)
    if type(card) == "number" then
        card = Fk:getCardById(card)
    end
    if card.type ~= Card.TypeEquip or (sub_type ~= nil and card.sub_type ~= sub_type) then return false end
    return card:getMark(curse) ~= 0
end

shengongcurse:addEffect(fk.AfterCardsMove, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        --local equips = player:getCardIds("e")
        --local room = player.room
        for _, move in ipairs(data) do
            if (move.to == player and move.toArea == Card.PlayerEquip) or (move.from == player) then
                for _, info in ipairs(move.moveInfo) do
                    local card = Fk:getCardById(info.cardId)
                    if (move.from == player and info.fromArea == Card.PlayerEquip) or move.to == player then
                        for k, v in pairs(card.mark) do
                            if k and k:startsWith("@@ym1__shengong") and v and v ~= 0 then
                                return true
                            end
                        end
                    end
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local equips = player:getCardIds("e")
        for _, move in ipairs(data) do
            if (move.to == player and move.toArea == Card.PlayerEquip) then
                local mark = {}
                table.filter(equips,function (id)
                    local card = Fk:getCardById(id)
                    local curse = {}
                    for k, v in pairs(card.mark) do
                        if k and k:startsWith("@@ym1__shengong") and v and v ~= 0 then
                            table.insert(curse,k)
                        end
                    end
                    if #curse > 0 then
                        table.insert(mark,card.name)
                        table.insertTable(mark,curse)
                    end
                end)
                if #mark > 0 then
                    room:setPlayerMark(player,"@[curse]ym1__curse",mark)
                else
                    room:setPlayerMark(player,"@[curse]ym1__curse",0)
                end
                for _, info in ipairs(move.moveInfo) do
                    local card = Fk:getCardById(info.cardId)
                    if hasCurse(card,"@@ym1__shengongB1",Card.SubtypeArmor) then
                        if not player.dead then
                            room:changeShield(player, 1)
                        end
                    end
                end
            elseif move.from == player then
                local mark = {}
                table.filter(player:getCardIds("e"),function (id)
                    local card = Fk:getCardById(id)
                    local curse = {}
                    for k, v in pairs(card.mark) do
                        if k and k:startsWith("@@ym1__shengong") and v and v ~= 0 then
                            table.insert(curse,k)
                        end
                    end
                    if #curse > 0 then
                        table.insert(mark,card.name)
                        table.insertTable(mark,curse)
                    end
                end)
                if #mark > 0 then
                    room:setPlayerMark(player,"@[curse]ym1__curse",mark)
                else
                    room:setPlayerMark(player,"@[curse]ym1__curse",0)
                end
                local gain = {}
                for _, info in ipairs(move.moveInfo) do
                    if hasCurse(info.cardId,"@@ym1__shengongC3") and (move.to ~= player or move.toArea ~= Card.PlayerHand) and Fk:getCardById(info.cardId):getMark("ym1__shengongC3-turn") == 0 then
                        room:setCardMark(Fk:getCardById(info.cardId),"ym1__shengongC3-turn",1)
                        table.insertIfNeed(gain,info.cardId)
                    end
                end
                if #gain > 0 then
                    room:moveCardTo(gain,Card.PlayerHand,player,fk.ReasonJustMove, "@@ym1__shengongC3", nil, true, player)
                end
            end
        end
    end,
})

shengongcurse:addEffect(fk.TargetSpecified, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        return target == player and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongA1",Card.SubtypeWeapon)
        end) and data.card.is_damage_card
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        data.to:addQinggangTag(data)
    end,
})

shengongcurse:addEffect(fk.EventPhaseStart, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        local room = player.room
        if target == player and player.phase == Player.Finish and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongA2",Card.SubtypeWeapon)
        end) then
            local targets = {}
            room.logic:getActualDamageEvents(1, function(e) table.insertIfNeed(targets, e.data.to) end)
            targets = table.filter(targets, function(p) return not p.dead end)
            return #targets > 0
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local targets = {}
        room.logic:getActualDamageEvents(1, function(e) table.insertIfNeed(targets, e.data.to) end)
        targets = table.filter(targets, function(tp) return not tp.dead end)
        for _, tp in ipairs(targets) do
            room:damage({
                from = player,
                to = tp,
                damage = 1,
                damageType = fk.FireDamage,
                skillName = nil,
            })
        end
    end,
})

shengongcurse:addEffect(fk.Damage, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        if target == player and data.card and data.card.trueName == "slash" and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongA3",Card.SubtypeWeapon)
        end) and not data.to.dead and not data.to:isNude() then
            return true
        end
        if target == player and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongA5",Card.SubtypeWeapon)
        end) and not data.to.dead then
            return true
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local equips = player:getCardIds("e")
        if target == player and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongA5",Card.SubtypeWeapon)
        end) and not data.to.dead then
            room:addPlayerMark(data.to, "@[desc]ym1__dun-round")
        end
        if target == player and data.card and data.card.trueName == "slash" and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongA3",Card.SubtypeWeapon)
        end) and not data.to.dead and not data.to:isNude() then
            local id = room:askToChooseCard(player, {
                target = data.to,
                flag = "he",
                skill_name = "@@ym1__shengongA3",
                prompt = "@@ym1__shengongA3-prompt",
            })
            if id ~= -1 then
                room:obtainCard(player,id,false)
            end
        end
    end,
})

shengongcurse:addEffect(fk.CardUsing, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        if target == player and data.card.trueName == "slash" and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongA4",Card.SubtypeWeapon)
        end) and data.tos and #data.tos > 0 then
            return true
        end
        if target == player and table.contains({"peach","analeptic"},data.card.trueName) and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongC1")
        end) then
            return true
        end
        if player == target and player:getMark("@[desc]ym1__dun-round") > 0 and data.card.type ~= Card.TypeEquip and
        data:isOnlyTarget(data.tos[1]) and not table.find(player.room.alive_players, function (p)
            return p.dying
        end) then
            return true
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local equips = player:getCardIds("e")
        if target == player and data.card.type == Card.TypeBasic and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongC1")
        end) then
            if data.card.name == "peach" then
                data.additionalRecover = (data.additionalRecover or 0) + 1
            elseif data.card.name == "analeptic" then
                if data.extra_data and data.extra_data.analepticRecover then
                    data.additionalRecover = (data.additionalRecover or 0) + 1
                else
                    data.extra_data = data.extra_data or {}
                    data.extra_data.additionalDrank = (data.extra_data.additionalDrank or 0) + 1
                end
            end
        end
        if target == player and data.card.trueName == "slash" and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongA4",Card.SubtypeWeapon)
        end) and data.tos and #data.tos > 0 then
            room.tag["@@ym1__shengongA4"] = room.tag["@@ym1__shengongA4"] or {}
            room.tag["@@ym1__shengongA4"][player.id] = room.tag["@@ym1__shengongA4"][player.id] or 0
            if not player.dead then
                local judge = {
                    who = player,
                    reason = "floating_thunder",
                    pattern = ".|.|spade",
                }
                room:judge(judge)
                if judge.card.suit == Card.Spade then
                    room.tag["@@ym1__shengongA4"][player.id] = room.tag["@@ym1__shengongA4"][player.id] + 1
                    room:damage{
                        to = player,
                        damage = room.tag["@@ym1__shengongA4"][player.id],
                        damageType = fk.ThunderDamage,
                        skillName = "@@ym1__shengongA4",
                    }
                end
            end
            for _, tp in ipairs(data:getAllTargets()) do
                local id = tp.id
                room.tag["@@ym1__shengongA4"][id] = room.tag["@@ym1__shengongA4"][id] or 0
                if not tp.dead then
                    local judge = {
                        who = tp,
                        reason = "floating_thunder",
                        pattern = ".|.|spade",
                    }
                    room:judge(judge)
                    if judge.card.suit == Card.Spade then
                        room.tag["@@ym1__shengongA4"][id] = room.tag["@@ym1__shengongA4"][id] + 1
                        room:damage{
                            to = tp,
                            damage = room.tag["@@ym1__shengongA4"][id],
                            damageType = fk.ThunderDamage,
                            skillName = "@@ym1__shengongA4",
                        }
                    end
                end
            end
        end
        if player == target and player:getMark("@[desc]ym1__dun-round") > 0 and data.card.type ~= Card.TypeEquip and
        data:isOnlyTarget(data.tos[1]) and not table.find(player.room.alive_players, function (p)
            return p.dying
        end) then
            room:removePlayerMark(player, "@[desc]ym1__dun-round")
            local targets = {}
            for _, p in ipairs(room.alive_players) do
                if not player:isProhibited(p, data.card) and
                    (data.card.sub_type == Card.SubtypeDelayedTrick or
                    data.card.skill:modTargetFilter(player, p, {}, data.card, data.extra_data)) then
                    table.insert(targets, p)
                end
            end
            if #targets > 0 then
                local random_target = table.random(targets)
                if #targets > 1 then
                    for _ = 1, 2 do
                        for _, p in ipairs(room:getAllPlayers()) do
                            if table.contains(targets, p) then
                                room:setEmotion(p, "./image/anim/selectable")
                                room:notifyMoveFocus(p, shengongcurse.name)
                                room:delay(300)
                            end
                        end
                    end
                    for _, p in ipairs(room:getAllPlayers()) do
                        if table.contains(targets, p) then
                            room:setEmotion(p, "./image/anim/selectable")
                            room:delay(600)
                            if p.id == random_target then
                                room:doIndicate(data.from, {random_target})
                                break
                            end
                        end
                    end
                end

                if random_target == data.tos[1] then
                    data.extra_data = data.extra_data or {}
                    data.extra_data.ym1__dunxi_record = data.extra_data.ym1__dunxi_record or {}
                    table.insert(data.extra_data.ym1__dunxi_record, player.id)
                    data.extra_data.ym1__dunxi_record = data.extra_data.ym1__dunxi_record
                else
                    data:removeTarget(data.tos[1])
                    data:addTarget(random_target)
                end
            else
                data:removeAllTargets()
            end
        end
    end,
})

shengongcurse:addEffect(fk.CardUseFinished, {
    can_refresh = function(self, event, target, player, data)
        return not player.dead and data.extra_data and data.extra_data.ym1__dunxi_record and
        table.contains(data.extra_data.ym1__dunxi_record, player.id)
    end,
    on_refresh = function (self, event, target, player, data)
        player.room:loseHp(player, 1, shengongcurse.name)
        if player.phase == Player.Play then
            player:endPlayPhase()
        end
    end,
})

shengongcurse:addEffect(fk.DamageInflicted, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        if target == player and data.damage > 1 and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongB2",Card.SubtypeArmor)
        end) then
            return true
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local equips = player:getCardIds("e")
        room:sendLog{
            type = "#BreastplateSkill",
            from = player.id,
            arg = "@@ym1__shengongB2",
            arg2 = data.damage,
            arg3 = Fk:getDamageNatureName(data.damageType),
        }
        room:moveCardTo(table.filter(equips, function(id) return hasCurse(id,"@@ym1__shengongB2",Card.SubtypeArmor) end),
        Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, shengongcurse.name, nil, true, player.id)
        local mark = {}
        table.filter(equips,function (id)
            local card = Fk:getCardById(id)
            local curse = {}
            for k, v in pairs(card.mark) do
                if k and k:startsWith("@@ym1__shengong") and v and v ~= 0 then
                    table.insert(curse,k)
                end
            end
            if #curse > 0 then
                table.insert(mark,card.name)
                table.insertTable(mark,curse)
            end
        end)
        if #mark > 0 then
            room:setPlayerMark(player,"@[curse]ym1__curse",mark)
        else
            room:setPlayerMark(player,"@[curse]ym1__curse",0)
        end
        data.damage = -999
        return true
    end,
})

shengongcurse:addEffect(fk.Damaged, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        if target == player and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongB3",Card.SubtypeArmor)
        end) and data.from and data.from.id ~= player.id and not data.from.dead and not data.from:isNude() then
            return true
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local cid = room:askToChooseCard(player, {
            target = data.from,
            flag = "he",
            skill_name = "@@ym1__shengongB3",
            prompt = "@@ym1__shengongB3-prompt",
        })
        room:throwCard({cid}, shengongcurse.name, data.from, player)
    end,
})

shengongcurse:addEffect(fk.AskForRetrial, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        return target == player and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongC2")
        end)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local equips = player:getCardIds("e")
        for _, id in ipairs(equips) do
            if hasCurse(id,"@@ym1__shengongC2") then
                if room:askToSkillInvoke(player,{
                    skill_name = "@@ym1__shengongC2",
                    prompt = "@@ym1__shengongC2-prompt",
                }) then
                    local move1 = {
                        ids = room:getNCards(1),
                        toArea = Card.Processing,
                        moveReason = fk.ReasonJustMove,
                        skillName = "@@ym1__shengongC2",
                        proposer = player.id,
                    }
                    local move2 = {
                        ids = {data.card:getEffectiveId()},
                        toArea = Card.DiscardPile,
                        moveReason = fk.ReasonJustMove,
                        skillName = "@@ym1__shengongC2",
                    }
                    room:moveCards(move1, move2)
                    data.card = Fk:getCardById(move1.ids[1])
                    room:sendLog{
                        type = "#ChangedJudge",
                        from = player.id,
                        to = {player.id},
                        card = {move1.ids[1]},
                        arg = "@@ym1__shengongC2",
                    }
                else
                    break
                end
            end
        end
    end,
})

shengongcurse:addEffect(fk.BeforeCardsMove, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        if table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongD1",Card.SubtypeWeapon)
        end) then
            for _, move in ipairs(data) do
                if move.from == player and move.moveReason == fk.ReasonUse then
                    for _, info in ipairs(move.moveInfo) do
                        local card = Fk:getCardById(info.cardId)
                        if card.trueName == "slash" then
                            return true
                        end
                    end
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        for _, move in ipairs(data) do
            if move.from == player and move.moveReason == fk.ReasonUse then
                local move_info = {}
                for _, info in ipairs(move.moveInfo) do
                    if Fk:getCardById(info.cardId).name ~= "slash" then
                        table.insert(move_info, info)
                    end
                end
                move.moveInfo = move_info
            end
        end
    end,
})

shengongcurse:addEffect(fk.BeforeDrawCard, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        local room = player.room
        local events = room.logic:getEventsOfScope(GameEvent.MoveCards, 2, function(e)
            local eventData = e.data
            for _, move in ipairs(eventData) do
                if move.to == player and move.moveReason == fk.ReasonDraw then
                    return true
                end
            end
            return false
        end, Player.HistoryTurn)
        return table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongC5")
        end) and target == player and #events == 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        data.num = 4
        local drawEvent = room.logic:getCurrentEvent().parent
        if data.skillName == "recast" then
            drawEvent = room.logic:getCurrentEvent()
        end
        drawEvent:addCleaner(function ()
            room:askToDiscard(player, {
                max_num = 2,
                min_num = 2,
                include_equip = true,
                skill_name = shengongcurse.name,
                cancelable = false,
                pattern = ".",
            })
        end)
    end,
})

shengongcurse:addEffect(fk.PreHpRecover, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        if target == player then
            for _, id in ipairs(equips) do
                local curse = {}
                local card = Fk:getCardById(id)
                for k, v in pairs(card.mark) do
                    if k and k:startsWith("@@ym1__shengong") and v and v ~= 0 then
                        table.insert(curse,k)
                    end
                end
                if #curse < 5 and hasCurse(id,"@@ym1__shengongC6") then
                    return true
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local equips = player:getCardIds("e")
        if target == player then
            for _, id in ipairs(equips) do
                local curses = {}
                local card = Fk:getCardById(id)
                for k, v in pairs(card.mark) do
                    if k and k:startsWith("@@ym1__shengong") and v and v ~= 0 then
                        table.insert(curses,k)
                    end
                end
                if #curses < 5 and hasCurse(id,"@@ym1__shengongC6") then
                    local sub_type = card.sub_type
                    local curse = {}
                    if sub_type == Card.SubtypeWeapon then
                        curse = {"@ym1__shengongA1","@ym1__shengongA2","@ym1__shengongA3","@ym1__shengongA4","@ym1__shengongA5",
                        "@ym1__shengongC1","@ym1__shengongC2","@ym1__shengongC3","@ym1__shengongC4","@ym1__shengongC5","@ym1__shengongC6"}
                        --[[if string.find(Fk:translate(card.name, "zh_CN"), "弓") ~= nil then
                            table.insert(curse,"@ym1__shengongD1")
                        end]]--
                    elseif sub_type == Card.SubtypeArmor then
                        curse = {"@ym1__shengongB1","@ym1__shengongB2","@ym1__shengongB3","@ym1__shengongB4",
                        "@ym1__shengongC2","@ym1__shengongC3","@ym1__shengongC4","@ym1__shengongC6"}
                    elseif table.contains({Card.SubtypeOffensiveRide,Card.SubtypeDefensiveRide},sub_type) then
                        curse = {"@ym1__shengongB2","@ym1__shengongD2",
                        "@ym1__shengongC2","@ym1__shengongC3","@ym1__shengongC4","@ym1__shengongC6"}
                    else
                        curse = {"@ym1__shengongC1","@ym1__shengongC2","@ym1__shengongC3","@ym1__shengongC4","@ym1__shengongC6"}
                    end
                    for _, str in ipairs(curse) do
                        if card:getMark("@"..str) == 1 then
                            table.removeOne(curse,str)
                        end
                    end
                    if #curse > 0 then
                        local choice = table.random(curse)
                        room:setCardMark(card,"@"..choice,1)
                        room:sendLog{
                            type = "#ym1__shengong-log",
                            from = player.id,
                            arg = "@@ym1__shengongC6",
                            arg2 = card:toLogString(),
                            arg3 = choice,
                            toast = true,
                        }
                    end
                end
            end
            local mark = {}
            table.filter(equips,function (id)
                local card = Fk:getCardById(id)
                local curse = {}
                for k, v in pairs(card.mark) do
                    if k and k:startsWith("@@ym1__shengong") and v and v ~= 0 then
                        table.insert(curse,k)
                    end
                end
                if #curse > 0 then
                    table.insert(mark,card.name)
                    table.insertTable(mark,curse)
                end
            end)
            if #mark > 0 then
                room:setPlayerMark(player,"@[curse]ym1__curse",mark)
            else
                room:setPlayerMark(player,"@[curse]ym1__curse",0)
            end
        end
    end,
})

shengongcurse:addEffect(fk.CardEffectCancelledOut, {
    global = true,
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        if target == player and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongD2",Card.SubtypeOffensiveRide) or hasCurse(id,"@@ym1__shengongD2",Card.SubtypeDefensiveRide)
        end) and data.to and data.to:isAlive() then
            return true
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local equips = player:getCardIds("e")
        if target == player and table.find(equips,function (id)
            return hasCurse(id,"@@ym1__shengongD2",Card.SubtypeOffensiveRide) or hasCurse(id,"@@ym1__shengongD2",Card.SubtypeDefensiveRide)
        end) and data.to and data.to:isAlive() then
            room:damage {
                from = data.to,
                to = tardata.toget,
                damage = 1,
                damageType = fk.IceDamage,
            }
        end
    end,
})

shengongcurse:addEffect("prohibit", {
    prohibit_use = function (self, player, card)
        if card.type == Card.TypeEquip then
            local equips = player:getCardIds("e")
            for _, id in ipairs(equips) do
                local equip = Fk:getCardById(id)
                if equip:getMark("@@ym1__shengongC4") == 1 and equip.sub_type == card.sub_type then
                    return true
                end
            end
        end
    end,
    global = true,
})

shengongcurse:addEffect("maxcards", {
    correct_func = function (self, player)
        local equips = player:getCardIds("e")
        local add = 0
        for _, id in ipairs(equips) do
            local equip = Fk:getCardById(id)
            if equip:getMark("@@ym1__shengongB4") == 1 then
                add = add + 2
            end
        end
        return add
    end,
    global = true,
})



return shengongcurse